<template>
  <div>
    <el-table
        ref="multipleTable"
        :data="tableData"
        tooltip-effect="dark"
        style="width: 100%"
        @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55"></el-table-column>
      <el-table-column label="任务编号" prop="taskId" />
      <el-table-column label="任务名称" prop="taskName" />
      <el-table-column label="发布人" prop="leaderName" />
      <el-table-column label="时间" prop="time" />
      <el-table-column label="具体内容" prop="taskRemark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template v-slot="scope">
          <el-button size="mini" type="text" @click="addWorkContent(scope.row)">上报工作内容</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-dialog center title="上报工作详情" :visible.sync="workContentDialog" width="700px" append-to-body>
      <el-form ref="form" label-width="80px" :model="recordForm">
        <el-row>
          <el-col :span="12">
            <el-form-item label="任务ID" prop="nickName"><el-input :disabled="true" v-model="taskInfo.taskId" placeholder="请输入" /></el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="任务名称" prop="nickName"><el-input :disabled="true" v-model="taskInfo.taskName" placeholder="请输入" /></el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="工作内容"><el-input type="textarea" v-model="recordForm.workContent" placeholder="请输入" /></el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="备注"><el-input type="textarea" v-model="recordForm.remarks" placeholder="请输入" /></el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitOperation">确 定</el-button>
        <el-button @click="workContentDialog=false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {formatDate} from "@/utils";
export default {
  name: "ProductRecordView",
  data(){
    return{
      tableData:[],
      recordForm:{},
      workContentDialog:false,
      taskInfo:''
    }
  },methods:{
    handleSelectionChange(selection) {
      this.ids=selection.map(item => item.dictCode).join(",")
    },
    getList(){
      this.axios.get("/product/product/queryTaskList").then(res=>{
        this.tableData=res.data.data
      })
    },
    addWorkContent(row){
      this.taskInfo = row
      this.workContentDialog = true
    },
    submitOperation(){
      const operationArray = []
      const id = new this.$snowFlakeId().generate()
      operationArray.push(id)
      operationArray.push(id)
      operationArray.push(this.taskInfo.cropsId)
      operationArray.push("吴亦凡")
      operationArray.push("15532635123")
      operationArray.push(formatDate(new Date()))
      operationArray.push(this.recordForm.workContent)
      operationArray.push(this.recordForm.remarks)
      this.$httpBlock
          .post(this.$httpUrl + '/productapi/createOperation', { operationArray: operationArray })
          .then(res => {
            if (res.status === 200) {
              this.$message.success("数据上链成功");
              this.workContentDialog = false
            }
          })
          .catch(err => {
            this.$message.error('存储异常 ' + err);
          });
    }
  },created() {
    this.getList()
  }
}
</script>

<style scoped>

</style>